<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="d" uri="http://dgg.net/jsp/jstl/core" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!--历史记录页面，用加载更多的方式显示-->
<input type="hidden" value="${order.id}" id="orderId">
<div class="dggui-tab-item dggui-show">
    <label>备注节点：</label>
    <select class="dggui-select" id="note_type">
        <option value="">请选择</option>
        <c:forEach var="remarksnode" items="${productNodes}">
            <option value="${remarksnode.id}">${remarksnode.name}</option>
        </c:forEach>
    </select>
    <div class="textarea-warp">
        <textarea class="dggui-textarea" id="note_detail" placeholder="添加备注信息" rows="4"></textarea>
    </div>
    <button class="dggui-btn" onclick="saveremarkByDetail()">保存</button>
    <h4>备注信息
        <select class="dggui-select" id="note_phase" onchange="loadHistory()">
            <option value="">全部</option>
            <c:forEach var="allRemarksNode" items="${allRemarksNodeList}">
                <option value="${allRemarksNode.id}">${allRemarksNode.name}</option>
            </c:forEach>
        </select>
    </h4>
    <ul class="rmark-list">
    </ul>
    <div class="dggui-more-no">
        <a href="javascript:void(0)" class="dggui-btn dggui-btn-primary dggui-btn-sm" onclick="getMoreHistory();">加载更多</a>
    </div>
</div>
<script>
    var page = 1;//当前页码
    var length = 6;//每页显示多少条
    $(function(){
        loadHistory();
    });
    /**
     * 加载更多历史记录
     */
    function getMoreHistory(){
        dggui.dialog.loading();
        $.post(sysInfo.basePath+"/order_detail/get_history.do",{scProductOrderId:$("#orderId").val(),optstate:$("#note_phase").val(),length:length,start:getStartCount()},function(result){
            dggui.dialog.loading('close');
            if(result.code==0){
                var list = result.data;
                if(list.length > 0){
                    var tHtm = new Array();
                    var htm = new Array();
                    for(var i=0;i<list.length;i++){
                        htm.push("<li><p>");
                        htm.push(list[i].remark);
                        htm.push("<p><div class=\"remark-list-info\"><span>");
                        htm.push(list[i].nodeName);
                        htm.push("</span><span>");
                        htm.push(list[i].createrName);
                        htm.push("</span><span>");
                        htm.push(list[i].createrOrgName);
                        htm.push("</span><span>");
                        htm.push(list[i].createTime);
                        htm.push("</span></div></li>");
                        tHtm.push(htm.join(''));
                        htm.length = 0;
                    }
                    $(".rmark-list").append(tHtm.join(''));
                    page += 1;
                }else{
                    $(".dggui-more-no").html("<span>没有更多的数据了</span>");
                }
            }else{
                dggui.dialog.errors(result.msg);
            }
        },'json');
    }
    function getStartCount(){
        return (page-1)*length;
    }
    /**
     * 刷新历史记录
     */
    function loadHistory(){
        console.log({scProductOrderId:$("#orderId").val(),optstate:$("#note_phase").val(),length:length,start:getStartCount()})
        page = 1;
        dggui.dialog.loading();
        $.post(sysInfo.basePath+"/order_detail/get_history.do",{scProductOrderId:$("#orderId").val(),optstate:$("#note_phase").val(),length:length,start:getStartCount()},function(result){
            dggui.dialog.loading('close');
            if(result.code==0){
                var list = result.data;
                if(list.length > 0){
                    var tHtm = new Array();
                    var htm = new Array();
                    for(var i=0;i<list.length;i++){
                        htm.push("<li><p>");
                        htm.push(list[i].remark);
                        htm.push("<p><div class=\"remark-list-info\"><span>");
                        htm.push(list[i].nodeName);
                        htm.push("</span><span>");
                        htm.push(list[i].createrName);
                        htm.push("</span><span>");
                        htm.push(list[i].createrOrgName);
                        htm.push("</span><span>");
                        htm.push(list[i].createTime);
                        htm.push("</span></div></li>");
                        tHtm.push(htm.join(''));
                        htm.length = 0;
                    }
                    $(".rmark-list").html(tHtm.join(''));
                    page += 1;
                    $(".dggui-more-no").html("<a href=\"javascript:void(0)\" class=\"dggui-btn dggui-btn-primary dggui-btn-sm\" onclick=\"getMoreHistory();\">加载更多</a>");
                }else{
                    $(".rmark-list").html('');
                    $(".dggui-more-no").html("<span>没有更多的数据了</span>");
                }
            }else{
                dggui.dialog.errors(result.msg);
            }
        },'json');
    }


    function saveremarkByDetail() {
        var productOrderId = $('#orderId').val();
        var nodeId = $('#note_type').val();
        var nodeName = $('#note_type').find("option:selected").text();
        var remark = $('#note_detail').val();
        if(!verifyEmpty($('#note_type'),"请选择备注节点！"))
            return false;
        if(!verifyEmpty($('#note_detail'),"备注信息不能为空！"))
            return false;
        dggui.dialog.confire("确定保存备注吗？", "生产备注", function () {
            dggui.dialog.loading();
            $.ajax({
                type: 'POST',
                data: {
                    nodeId: nodeId,
                    nodeName: nodeName,
                    remark: remark,
                    productOrderId: productOrderId
                },
                url: sysInfo.basePath + '/order_detail/save_product_operating_by_detail.do',
                dataType: 'JSON',
                success: function (data) {
                    dggui.dialog.loading('close');
                    if (data.code != 0) {
                        dggui.dialog.errors(data.msg);
                    } else {
                        dggui.dialog.succeed("操作成功!");
                        $('#note_detail').val('');
                        loadHistory();
                        //window.location.reload();
                    }
                },
                error: function () {
                    dggui.dialog.errors('保存失败，请联系管理员！');
                }
            })
        })
    }
</script>